#!/usr/bin/env python
# coding:utf-8
# @author heitfei

'''
udp time server using socket
'''

import socket
import time

HOST = ''
PORT = 23567
ADDR = (HOST, PORT)
BUFFSIZE = 1024

udpSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
udpSocket.bind(ADDR)

while True:
    print 'waiting for message ...'
    data, addr = udpSocket.recvfrom(BUFFSIZE)
    udpSocket.sendto("[%s] %s" % (time.ctime(), data), addr)
    print '... received from and returned to:',addr

udpSocket.close()